package test.spring;

import java.lang.reflect.Field;

import javax.persistence.Table;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import entity.newEn.ChangeInfo;
import entity.newEn.ExecutionPlanInfo;
import entity.newEn.SqlVerifyInfo;
import entity.newEn.User;
//import entity.newEn.SqlVerifyInfo;

import spring.dao.JdbcDaoImpl;
import spring.dao.JdbcDaoImpl1;

public class InsertData {
	public static void main(String[] args) {
		User ci = new User();
		//SqlVerifyInfo ci = new SqlVerifyInfo();
		//ChangeInfo ci = new ChangeInfo();
		//ExecutionPlanInfo ci = new ExecutionPlanInfo();
		
        ApplicationContext ctx = new ClassPathXmlApplicationContext(
                        "test.xml");

       JdbcDaoImpl1 dao = ctx.getBean("jdbcDaoimpl1", JdbcDaoImpl1.class);
        dao.nothing();
      
        String tableName = ci.getClass().getAnnotation(Table.class).name();
        
     
        // System.out.println(ci.getClass().getAnnotation(Table.class).name());
        Field[] fs = ci.getClass().getDeclaredFields();

        for (int i = 1; i < 200; i++) {
                String sql = "insert into " + tableName + " (";
                String valuesString = "values (";
                for (Field field : fs) {
                        sql += field.getName() + ",";
                        if (field.getType().getName()=="int") {
                                valuesString += i + ",";
                        } else {

                                valuesString += "'" + field.getName() + i + "',";
                        }
                }
                sql = sql.substring(0, sql.length() - 1) + ")";
                String query = sql + valuesString;
                String tempsql = query.substring(0, query.length() - 1) + ")";

                dao.getJdbcTemplate()
                                .update(tempsql);

                System.out.println(tempsql);
        }
	}
}
